using UnityEngine;
using System.Collections;

public class Scores : MonoBehaviour
{
    static private int cols = 2;
    static private int rows = 5;
    public UIFont font;
    private UITable uitable;
    private GameObject table;
    private string playerName;
    private GameObject[,] listOfLabel = new GameObject[cols, rows];

    void FillScoreTable()
    {
        Data.Sort();

        Color nameColor = new Color(0, 1, 0, 1);
        Color scoreColor = new Color(1, 1, 0, 1);

        for (int i=0; i<rows; i++)
        {
            var label = listOfLabel[0, i].gameObject.GetComponent<UILabel>();
            label.text = Data.arrayOfName[i];
            label.color = nameColor;
        }

        for (int i=0; i<rows; i++)
        {
            var label = listOfLabel[1, i].gameObject.GetComponent<UILabel>();
            label.text = Data.arrayOfScore[i] + "";
            label.color = scoreColor;
        }
    }

    void Start()
    {
		Data.LoadData();

        table = new GameObject("tableScores");
        table.transform.parent = this.gameObject.transform;
        uitable = table.AddComponent<UITable>();
		
        uitable.padding = new Vector2(0.5f, 0.5f);
		
        uitable.columns = cols;
        uitable.direction = UITable.Direction.Down;
		
        for (int i=0; i<rows; i++)
        {
            for (int j=0; j<cols; j++)
            {
                GameObject obj = new GameObject("label");
                var label = obj.AddComponent<UILabel>();
                label.font = font;
                label.text = " ";
				
                obj.transform.localScale = new Vector3(1.1f, 1.1f, 1.1f);
				
                obj.transform.parent = table.transform;
				
                listOfLabel[j, i] = obj;
            }
        }

		
        table.transform.localScale = new Vector3(72.2f, 50.0f, 1.0f);
        table.transform.localPosition = new Vector3(-223.0f, 335.0f, 0);

        FillScoreTable();
    }
}